<?php
namespace Manager\Controller;
/**
* ==============================================
* URL：http://www.liuhuanhui.cn
* ==============================================
* @date：2014-10-20
* @time：下午8:20:03
* @author：liuhuanhui
* @encoding：UTF-8
*/
class NavigateController extends AuthController
{
	/**
	 * 显示导航信息
	 */
	function  index()
	{
		$this->navs=ParentChild(M('navs')->field('params,target',true)->order('orders')->select());
		$this->display();
	}
	/**
	 * 修改导航信息
	 */
	function update_IShide()
	{
		
		if(M('navs')->save($_GET))
			$this->success('修改状态成功！');
		else
			$this->error('修改状态失败！');
	}
	/**
	 * 编辑导航信息
	 */
	function edit()
	{	
		$this->pages=M('blogs')->field('id,title')->select();
		$this->sorts=M('sorts')->field('id,name')->order('number')->select();
		$this->parents=M('navs')->where('parent=0')->field('id,title')->order('orders')->select();
		
		$nav=M('navs')->find($_GET['id']);
		if($nav['navtype']=='url'||$nav['navtype']=='df')
			$this->assign('url',$nav);
		else if($nav['navtype']=='sort')
			$this->assign('sort',$nav);
		else 
			$this->assign('page',$nav);
		$this->navtype=$nav['navtype'];
		$this->display('create');
	}
	/**
	 * 新增导航
	 */
	function create()
	{
		$this->pages=M('blogs')->field('id,title')->select();
		$this->sorts=M('sorts')->field('id,name')->order('number')->select();
		$this->parents=M('navs')->where('parent=0')->field('id,title')->order('orders')->select();

		$this->display();
	}
	/**
	 * 删除导航信息
	 */
	function delete()
	{		
		$nav=M('navs');
		if($nav->delete($_GET['id']))
		{
			$nav->where('parent='.$_GET['id'])->delete();
			$this->success('删除导航成功！');
		}else
			$this->error('删除导航失败！');
	}
	/**
	 * 添加和修改的处理方法
	 */
	function insertAndUpdateHandle()
	{
		if(EMPTY($_POST['id']))
		{
			if($_POST['navtype']=='sort')
				$_POST['href']='/Sort/'.I('params');
			else if($_POST['navtype']=='page')
			{
				$_POST['href']='/Article/'.I('params');
			}
			if(M('navs')->add($_POST))
				$this->success('添加导航菜单成功！',U('index'));
			else
				$this->error('添加导航菜单失败！');
		}
		else
		{
				if(M('navs')->save($_POST))
				$this->success('修改导航菜单成功！',U('index'));
			else
				$this->error('修改导航菜单失败！');
		}

	}
	
}